define(['angular', 'config', 'services'], function (angular, config) {
	'use strict';

	/* Controllers */

	return angular.module('myApp.controllers', ['myApp.services'])
		// Sample controller where service is being used
		.controller('MyCtrl1', ['$scope', 'version', function ($scope, version) {
			$scope.scopedAppVersion = version;
		}])
		// More involved example where controller is required from an external file
		.controller('MyCtrl2', ['$scope', '$injector', 'restService', function($scope, $injector, restService) {
			$scope.books = [];

			function changePage(num){
				var index = num * 5;
				var url = config.url.SEARCH_BOOK;
				var data = {
					q: 'love',
					count: 5,
					start: index
				};
				//rest service usage
				restService.get(url, data, function(data){
					var books = [];
					data.books.forEach(function(item){
						books.push({
							title: item.title,
							imageUrl: item.image,
							price: item.price
						});
					});
					$scope.books = books;
				});
			}

			changePage(0);

			$scope.changePage = function(){
				changePage(this.$index);
			};

			require(['controllers/myctrl2'], function(myctrl2) {
				// injector method takes an array of modules as the first argument
				// if you want your controller to be able to use components from
				// any of your other modules, make sure you include it together with 'ng'
				// Furthermore we need to pass on the $scope as it's unique to this controller
				$injector.invoke(myctrl2, this, {'$scope': $scope});
			});
		}]);
});
